package com.ruoyi.web.controller.dgw;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dgw.domain.CowAbnormal;
import com.ruoyi.dgw.service.ICowAbnormalService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 异常Controller
 * 
 * @author ruoyi
 * @date 2022-02-23
 */
@RestController
@RequestMapping("/dgw/abnormal")
public class CowAbnormalController extends BaseController
{
    @Autowired
    private ICowAbnormalService cowAbnormalService;

    /**
     * 查询异常列表
     */
    @PreAuthorize("@ss.hasPermi('dgw:abnormal:list')")
    @GetMapping("/list")
    public TableDataInfo list(CowAbnormal cowAbnormal)
    {
        startPage();
        List<CowAbnormal> list = cowAbnormalService.selectCowAbnormalList(cowAbnormal);
        return getDataTable(list);
    }

    /**
     * 导出异常列表
     */
    @PreAuthorize("@ss.hasPermi('dgw:abnormal:export')")
    @Log(title = "异常", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CowAbnormal cowAbnormal)
    {
        List<CowAbnormal> list = cowAbnormalService.selectCowAbnormalList(cowAbnormal);
        ExcelUtil<CowAbnormal> util = new ExcelUtil<CowAbnormal>(CowAbnormal.class);
        return util.exportExcel(list, "异常数据");
    }

    /**
     * 获取异常详细信息
     */
    @PreAuthorize("@ss.hasPermi('dgw:abnormal:query')")
    @GetMapping(value = "/{abnormalId}")
    public AjaxResult getInfo(@PathVariable("abnormalId") String abnormalId)
    {
        return AjaxResult.success(cowAbnormalService.selectCowAbnormalByAbnormalId(abnormalId));
    }

    /**
     * 新增异常
     */
    @PreAuthorize("@ss.hasPermi('dgw:abnormal:add')")
    @Log(title = "异常", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CowAbnormal cowAbnormal)
    {
        return toAjax(cowAbnormalService.insertCowAbnormal(cowAbnormal));
    }

    /**
     * 修改异常
     */
    @PreAuthorize("@ss.hasPermi('dgw:abnormal:edit')")
    @Log(title = "异常", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CowAbnormal cowAbnormal)
    {
        return toAjax(cowAbnormalService.updateCowAbnormal(cowAbnormal));
    }

    /**
     * 删除异常
     */
    @PreAuthorize("@ss.hasPermi('dgw:abnormal:remove')")
    @Log(title = "异常", businessType = BusinessType.DELETE)
	@DeleteMapping("/{abnormalIds}")
    public AjaxResult remove(@PathVariable String[] abnormalIds)
    {
        return toAjax(cowAbnormalService.deleteCowAbnormalByAbnormalIds(abnormalIds));
    }
}
